# -*- coding: utf-8 -*-
# @Time    : 2021/4/22 21:12
# @Author  : xxue
# @Email   : x_xue1212@163.com
# @File    : 4-22 三创-爬虫.py
# @Software: PyCharm


# 三创爬虫
import re
import requests
sc="http://www.sanchuangedu.cn"
result = requests.get("http://www.sanchuangedu.cn/")
# <img src="/upload/teacher/%E4%BB%98%E6%96%97%E5%B9%B32.jpg">
ret=re.findall(r'(?:<img\s\w*=\")(.*?)\"',result.text)
n = 0
for i in ret:
    st = i.split('.')
    # 获取图片后缀名
    n += 1

    if sc in i:
        # 判断sc是否在i里
        fp.write(i)
    else:
        i = ''.join([sc, i])

    request = requests.get(i)
    with open(f"img/{n}.{st[1]}", 'wb') as f:
        f.write(request.content)




